package dao;

import model.Movimentacao;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class MovimentacaoDAO {

	protected String tableName = "Movimentacao";

	protected SQLiteDatabase database = null;

	protected Context context = null;

	public MovimentacaoDAO(Context ctx) {
		database = ctx.openOrCreateDatabase("gigo_financeiro",
				Context.MODE_PRIVATE, null);
		context = ctx;
	}

	protected long insert(Movimentacao object) {
		ContentValues content = new ContentValues();
		content.put("titulo", object.getTitulo());
		content.put("valor", object.getValor());
		content.put("dataoperacao", object.getDataOperacao().toString());
		content.put("tipooperacao", object.getTipoOperacao());
		return database.insert(tableName, null, content);
	}

	protected int update(Movimentacao object) {
		ContentValues content = new ContentValues();
		content.put("titulo", object.getTitulo());
		content.put("valor", object.getValor());
		content.put("dataoperacao", object.getDataOperacao().toString());
		content.put("tipooperacao", object.getTipoOperacao());
		return database.update(tableName, content, "where idmovimentacao = ?",
				new String[] { String.valueOf(object.getId()) });
	}

	protected int delete(Movimentacao object) {
		return database.delete(tableName, "where idmovimentacao = ?",
				new String[] { String.valueOf(object.getId()) });
	}

}
